package com.dinzeer.godfox.se;

import com.dinzeer.godfox.regsiter.GBEffectRegsitry;
import com.dinzeer.godfox.regsiter.GBSpecialEffectsRegistry;
import com.dinzeer.legendreliclib.effect.LReffect;
import com.dinzeer.legendreliclib.lib.util.FastMakeEntityUtil;
import com.dinzeer.legendreliclib.lib.util.slashblade.AbstractSpecialEffect;
import com.dinzeer.legendreliclib.lib.util.slashblade.SlashBladeUtil;
import mods.flammpfeil.slashblade.event.SlashBladeEvent;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.registry.SpecialEffectsRegistry;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.IForgeRegistry;

@Mod.EventBusSubscriber
public class BloodFoxCurse extends AbstractSpecialEffect {
    public BloodFoxCurse() {
        super(30);
    }
    @Override
    public void handleUpdate(SlashBladeEvent.UpdateEvent event, LivingEntity attacker) {
        if (isEffctives(attacker)){
        FastMakeEntityUtil.FastEffect(attacker, GBEffectRegsitry.ForTheBlood.get(), 1);
        }
    }

    @Override
    public void handleHitEntity(SlashBladeEvent.HitEvent event, LivingEntity attacker) {
        if (isEffctives(attacker)){
            if (event.getTarget().hasEffect(LReffect.TheGreatRip.get())){
                int level=event.getTarget().getEffect(LReffect.TheGreatRip.get()).getAmplifier();
                if (level>2){
                    level=2;
                }
                FastMakeEntityUtil.FastEffect(event.getTarget(), LReffect.TheGreatRip.get(), 1+level);
            }else {
                FastMakeEntityUtil.FastEffect(event.getTarget(), LReffect.TheGreatRip.get(), 1);
            }
        }
    }

    @Override
    public void handleLivingHurt(LivingHurtEvent event, LivingEntity attacker) {
        if (isEffctives(attacker)){
            if (attacker.getRandom().nextInt(100)>89){
                FastMakeEntityUtil.FastHurt(attacker, attacker, event.getAmount(), DamageTypes.MOB_ATTACK);
            }
        }
    }

    private Boolean isEffctives(LivingEntity attacker){

        if (attacker instanceof Player player){
            return isEffective(this, player.experienceLevel);
        }
        return true;
    }
}
